#include "trayicon.h"

TrayIcon::TrayIcon()
{
    // Actions
    optionsAction = new QAction(tr("&Options"), this);
    connect(optionsAction, SIGNAL(triggered()), this, SLOT(doShowOptions()));
    aboutAction = new QAction(tr("&About"), this);
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(doShowAbout()));
    quitAction = new QAction(tr("&Quit"), this);
    connect(quitAction, SIGNAL(triggered()), this, SLOT(doQuit()));
    // Menu
    trayMenu = new QMenu();
    trayMenu->addAction(optionsAction);
    trayMenu->addAction(aboutAction);
    trayMenu->addSeparator();
    trayMenu->addAction(quitAction);
    // Icon
    trayIcon = new QSystemTrayIcon();
    trayIcon->setContextMenu(trayMenu);
    trayIcon->setIcon(QIcon(":/images/icon.png"));
    trayIcon->show();
}

void TrayIcon::doShowOptions()
{
    emit showOptions();
}

void TrayIcon::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
    if (reason == QSystemTrayIcon::Trigger)
        emit iconClicked();
}

void TrayIcon::doShowAbout()
{
    QString aboutText = tr("KCheckVkontakte 0.6<br>"\
                           "Messages notifier for http://vk.com/ social network"\
                           "<br>"\
                           "This program is Free Software and distributed<br>"\
                           "under GNU GPLv3.<br>"\
                           "(c) AG45Team, 2009");
    QWidget emptyWidget;
    emptyWidget.setWindowIcon(QIcon(":/images/icon.png"));
    QMessageBox::about(0, tr("About KCheckVkontakte"), aboutText);
}

void TrayIcon::doQuit()
{
    emit quit();
}
